var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var connectionsArray = [];
var mysql = require('mysql');
var connection = mysql.createConnection({
	// host: '27.148.148.123',
	// user: 'sedc',
	host: 'localhost',
	user: 'root',
	password: 'root',
	database: 'js60',
	port: 3306
});
// ������ݿ������Ƿ�����
connection.connect(function(err) {
	// �����ִ�����Ϣ���Ǳ�ʾ���ݿ����ӳɹ�
	//console.log(err);
});

//app.get('/', function(req, res){
//	res.send('<h1>Welcome Realtime Server</h1>');
//});

http.listen(3000, function(){
	console.log('listening on *:3000');
});

io.sockets.on('connection', function(socket) {
	//io.emit('abc', 'ddddddd');
	console.log('socket = ' + socket + ' connected');
	
	socket.on('disconnect', function() {
		console.log('socket = ' + socket + ' disconnected');
	});
	saaa();
});

function saaa() {
	//����һ��
	setTimeout(function () {
		io.emit('abc', 'ddddddd11');
	}, 1000);
	//ѭ������ 
	//setInterval(function () {
		
	//}, 1000);
}

